/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package mx.its.dsw2.escuela.bl;

import java.util.List;
import javax.ejb.EJB;
import javax.ejb.Stateless;
import mx.its.dsw2.escuela.dao.AlumnoDaoLocal;
import mx.its.dsw2.escuela.enumeracion.EstadoTransaccion;
import mx.its.dsw2.escuela.modelo.Alumno;

/**
 *
 * @author Maq-8
 */
@Stateless
public class AlumnoBl implements AlumnoBlLocal {

    @EJB
    private AlumnoDaoLocal alumnoDao;

    @Override
    public EstadoTransaccion register(Alumno student) {
        if (alumnoDao.findByDuplicity(student)) {
            return EstadoTransaccion.INCOMPLETO;
        } else {
            alumnoDao.create(student);
            return EstadoTransaccion.COMPLETO;
        }
    }

    @Override
    public EstadoTransaccion modify(Alumno student) {
        if (student.getId() == null || alumnoDao.find(student.getId()) == null) {
            return EstadoTransaccion.INCOMPLETO;
        } else {
            alumnoDao.edit(student);
            return EstadoTransaccion.COMPLETO;
        }
    }

    @Override
    public EstadoTransaccion delete(Alumno student) {
        if (student.getId() == null || alumnoDao.find(student.getId()) == null) {
            return EstadoTransaccion.INCOMPLETO;
        } else {
            alumnoDao.remove(student);
            return EstadoTransaccion.COMPLETO;
        }
    }

    @Override
    public List<Alumno> getAll() {
        return alumnoDao.findAll();
    }

    @Override
    public Alumno findByNoControl(String noControlAlumno) {
        return alumnoDao.findStudentForAssistance(noControlAlumno);
    }
}
